package com.cmit.lee.myaop.interceptor;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;

/**
 * <br/>
 *
 * @author liyuanchang
 * @version V1.0
 * @email liyuanchang@chinamobile.com
 * @date 2020-04-15 21:02
 */
public abstract class AfterReturningInteceptor implements MethodInterceptor {
    public abstract void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable;

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        // 先执行目标方法获取到返回值
        Object retVal = invocation.proceed();
        this.afterReturning(retVal, invocation.getMethod(), invocation.getArguments(), invocation.getThis());
        // 返回
        return retVal;
    }
}
